﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using LeHouse.Server.Dto;
using LeHouse.Server.Service;
namespace LeHouse.Server.WebApi.Controllers
{
    public class ZoneController : ApiController
    {
        Collateral_ZoneService bll = new Collateral_ZoneService();
        /// <summary>
        /// 抵押物区位状况的数据添加
        /// </summary>
        /// <param name="s">ajax传过来的需要添加的数据</param>
        /// <returns></returns>       
        [HttpPost]
        [Route("api/Zone/Postinsert")]
        public bool Insert([FromBody] Collateral_Zone parms)
        {
            if (count(parms.T_ReportNumber) > 0)
            {
                Collateral_Zone parms1 = new Dto.Collateral_Zone();
                parms1.T_ReportNumber = parms.T_ReportNumber;
                parms1.T_SurroundID = parms.T_SurroundID;
                parms1.T_Master = parms.T_Master;
                parms1.T_South = parms.T_South;
                parms1.T_Western = parms.T_Western;
                parms1.T_North = parms.T_North;
                parms1.T_TrafficID = parms.T_TrafficID;
                parms1.T_Traffic = parms.T_Traffic;
                parms1.T_NatureID = parms.T_NatureID;
                parms1.T_Nature = parms.T_Nature;
                parms1.T_DwellingID = parms.T_DwellingID;
                parms1.T_Dwelling = parms.T_Dwelling;
                parms1.T_InfrastructureID = parms.T_InfrastructureID;
                parms1.T_Infrastructure = parms.T_Infrastructure;
                parms1.T_SupportingID = parms.T_SupportingID;
                parms1.T_Explain = parms.T_Explain;
                Collateral_ZoneService insert = new Collateral_ZoneService();
                if (insert.Update(parms1, t => t.T_ReportNumber == parms.T_ReportNumber))
                {
                    return true;
                }
                else
                {
                    return false;
                }

            }
            else
            {
                Collateral_Zone parms1 = new Dto.Collateral_Zone();
                parms1.T_ReportNumber = parms.T_ReportNumber;
                parms1.T_SurroundID = parms.T_SurroundID;
                parms1.T_Master = parms.T_Master;
                parms1.T_South = parms.T_South;
                parms1.T_Western = parms.T_Western;
                parms1.T_North = parms.T_North;
                parms1.T_TrafficID = parms.T_TrafficID;
                parms1.T_Traffic = parms.T_Traffic;
                parms1.T_NatureID = parms.T_NatureID;
                parms1.T_Nature = parms.T_Nature;
                parms1.T_DwellingID = parms.T_DwellingID;
                parms1.T_Dwelling = parms.T_Dwelling;
                parms1.T_InfrastructureID = parms.T_InfrastructureID;
                parms1.T_Infrastructure = parms.T_Infrastructure;
                parms1.T_SupportingID = parms.T_SupportingID;
                parms1.T_Explain = parms.T_Explain;
                Collateral_ZoneService insert = new Collateral_ZoneService();
                if (insert.Insert(parms1) == true)
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }


        }

        //  <summary>
        // 查看抵押物区位状况表的所有数据by  id
        //  </summary>
        //   <returns></returns>
        [HttpGet]
        [Route("api/Zone/selectbyid")]
        public Collateral_Zone selectbyid([FromUri] string P_ReportNumber)
        {
            //var v = Request.Content;
            if (count(P_ReportNumber) > 0)
            {
                Collateral_ZoneService select = new Collateral_ZoneService();
                return select.Community(P_ReportNumber);
            }
            else
            {
                return null;
            }

        }
        /// <summary>
        /// 根据报告号去查询抵押物区位有该条记录
        /// </summary>
        /// <param name="P_ReportNumber"></param>
        /// <returns></returns>
        public int count(string P_ReportNumber)
        {
            return bll.count(P_ReportNumber);
        }


    }
}
